From 0a5f82bb9dd8d9169c4499bc7007c4f6daf372d5 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Mon, 10 Nov 2003 16:49:44 +0000 Subject: [PATCH] bitkeeper revision 1.582.1.2 (3fafc1a8WtDmHzijhEouIqSThPp1nA) xen_netwatch.c: Fixes to xen_netwatch. --- tools/misc/xen_netwatch.c | 47 +++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/tools/misc/xen_netwatch.c b/tools/misc/xen_netwatch.c index b4aac6da1b..d6624d5e30 100644 --- a/tools/misc/xen_netwatch.c +++ b/tools/misc/xen_netwatch.c @@ -1,7 +1,13 @@ /****************************************************************************** - * netwatch.c + * xen_netwatch.c * - * Watch for network interfaces needing frobbing. + * Watch for network interfaces changing state (IFF_UP), and call a standard + * script '/etc/xen/netwatch up|down'. Logging from the netwatch + * daemon is written to '/var/xen/netwatch' -- other programs can therefore + * watch that file to take action on interface state changes. + * + * Note that, apart from the names of the default action script and log file, + * this program is not actually Xen-dependent. * * Copyright (c) 2003, K A Fraser */ @@ -24,6 +30,9 @@ #include #include +#define DEFAULT_SCRIPT "/var/xen/netwatch" +#define DEFAULT_LOGFILE "/etc/xen/netwatch" + #define LOG(_f, _a...) \ do { \ time_t now = time(NULL); \ @@ -56,11 +65,10 @@ void handle_child_death(int dummy) int main(int argc, char **argv) { - char *logfile = "/var/xen/netwatch"; - char *scriptfile = "/etc/xen/netwatch"; + char *logfile = DEFAULT_LOGFILE; + char *scriptfile = DEFAULT_SCRIPT; FILE *logfd; - int nlfd, unixfd, bytes; - int last_index = ~0; + int i, nlfd, unixfd, bytes, last_index = ~0; unsigned int last_flags = ~0; char buffer[8192]; struct sockaddr_nl nladdr; @@ -69,6 +77,25 @@ int main(int argc, char **argv) struct ifreq ifr; struct sigaction sigchld; + for ( i = 1; i < argc; i++ ) + { + if ( strncmp("-s", argv[i], 2) == 0 ) + { + scriptfile = argv[i] + 2; + } + else if ( strncmp("-l", argv[i], 2) == 0 ) + { + logfile = argv[i] + 2; + } + else + { + printf("Usage: %s [-s